//
//  editAuidoWave_all.m
//  SoundPill
//
//  Created by 宋旭东®Des on 15/1/28.
//  Copyright (c) 2015年 宋旭东. All rights reserved.
//

#import "editAuidoWave_all.h"

@interface editAuidoWave_all ()

@property (strong, nonatomic) NSArray *waveArray;
@property (strong, nonatomic) NSArray *offset;
@end

@implementation editAuidoWave_all

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.waveArray = [[NSArray alloc] init];
        self.offset = [[NSArray alloc] init];
    }
    return self;
}

- (void)getAudioWaveArray:(NSArray *)array offsetArray:(NSArray *)offsetArray
{
    _waveArray = array;
    [self setNeedsDisplay];
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    CGFloat offset = 0;
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineCap(context, kCGLineCapSquare); //线条样式
    CGContextSetLineWidth(context, 1); //线条宽度
    //    CGContextSetRGBStrokeColor(context, 0.286, 0.776, 0.847, 1.00);
    CGContextSetRGBStrokeColor(context, 0.145, 0.145, 0.145, 0.3);
    CGContextBeginPath(context);
    for (int i = 0; i < [_waveArray count]; i++) {
        offset+=2;
        NSNumber *waveNum = _waveArray[i];
        float wave = waveNum.floatValue / 100 *self.frame.size.height;
        CGContextMoveToPoint(context, offset, self.frame.size.height / 2 + wave * 0.8);
        CGContextAddLineToPoint(context, offset, self.frame.size.height / 2 - wave * 1.2);
    }
    CGContextStrokePath(context);
}


@end
